03_Vynimky II/Over.html


  1  <?xml version="1.0" encoding="windows-1250"?>
  2  <!DOCTYPE html   PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  3    "DTD/xhtml1-strict.dtd">
  4  <html>
  5  <head>
  6    <title>Over číslo</title>
  7    <meta http-equiv="Author" content="Imrich BURANSKY" />
  8    <meta http-equiv="Content-Type" content="text/html; charset=windows-1250" />
  9    <script type="text/javascript">
 10      function Obj (id)
 11      { // Ziskanie objektu prvku so zadanou hodnotou atributu id
 12        if (document.getElementById) return document.getElementById(id); // W3C DOM
 13        if (document.all) return document.all[id];  // IE
 14        return null;
 15      }
 16      function Info (Oznam, Text)
 17      {
 18        while (Oznam.firstChild) Oznam.removeChild(Oznam.firstChild);
 19        if (Text!=null)
 20        { text = document.createTextNode(Text);
 21          Oznam.insertBefore(text, null);
 22        }
 23      }
 24      function Kontrola(Text, min, max )
 25      {
 26        if ( Text.search(/[^0-9]/g) != -1)
 27          throw "Je zadaný nečíselný znak" ;
 28        if (min!=null && Text < min)
 29          throw "Zadaná hodnota musí byť >= " + min;
 30        if (max!=null && Text > max)
 31          throw "Zadaná hodnota musí byť <= " + max;
 32      }
 33      function OverCislo(Vstup, Oznam, min, max)
 34      {
 35        try
 36        { Kontrola(Vstup.value, min, max);
 37          Info (Oznam, null);
 38        }
 39        catch (e)
 40        {
 41          Info (Oznam, e);
 42        }
 43      }
 44    </script>
 45  </head>
 46  <body>
 47  <h2>Kontrola zadaného čísla</h2>
 48    Zadajte čísla:
 49    <div>
 50      <input type="text" value="7" size="10"
 51        onkeyup="OverCislo(this, Obj('Ax'), 7, 77)"/>
 52      <span id="Ax" style="color:red;"> </span>
 53    </div>
 54    <div>
 55      <input type="text" value="8" size="10"
 56        onkeyup="OverCislo(this, Obj('Bx'), null, 77)"/>
 57      <span id="Bx" style="color:red;"></span>
 58    </div>
 59    <div>
 60      <input type="text" value="9" size="10"
 61        onkeyup="OverCislo(this, Obj('Cx'), 7, null)"/>
 62      <span id="Cx" style="color:red;"></span>
 63    </div>
 64  </body>
 65  </html>